<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible" width="60%">
    <!-- 列表 -->
    <ContentWrap>
      <el-table
        row-key="id"
        v-loading="loading"
        :data="list"
        :stripe="true"
        :show-overflow-tooltip="true"
      >
        <el-table-column label="日志类型" align="center" prop="logType" />
        <el-table-column label="关联单号" align="center" prop="linkId" />
        <el-table-column
          label="入库仓库"
          align="center"
          prop="inWarehouseId_dictText"
          v-if="formType === '退料' || formType === '入库'"
        />
        <el-table-column
          label="出库仓库"
          align="center"
          prop="outWarehouseId_dictText"
          v-if="formType === '领料'"
        />
        <el-table-column label="产品编码" align="center" prop="productId" />
        <el-table-column label="产品名称" align="center" prop="productName" />
        <el-table-column label="数量" align="center" prop="count" />
        <el-table-column label="单位" align="center" prop="productUnitId_dictText" />
        <el-table-column label="备注" align="center" prop="remark" />
        <el-table-column label="操作人" align="center" prop="creator_dictText" />
        <el-table-column
          label="操作时间"
          align="center"
          prop="createTime"
          :formatter="dateFormatter"
          width="180px"
        />

        <!--        <el-table-column label="操作" align="center" min-width="120px">-->
        <!--          <template #default="scope">-->
        <!--            <el-button-->
        <!--                link-->
        <!--                type="primary"-->
        <!--                @click="openForm('update', scope.row.id)"-->
        <!--                v-hasPermi="['erp:produce-plan-log:update']"-->
        <!--            >-->
        <!--              编辑-->
        <!--            </el-button>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
      </el-table>
      <!-- 分页 -->
      <Pagination
        :total="total"
        v-model:page="queryParams.pageNo"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </ContentWrap>
  </Dialog>
</template>

<script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime'
import { ProducePlanLog, ProducePlanLogApi } from '@/api/erp/produce/planLog'

/** ERP 生产计划日志 列表 */
defineOptions({ name: 'ProducePlanLog' })

const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题
const loading = ref(true) // 列表的加载中
const formType = ref('') // 表单的类型：create - 新增；update - 修改
const list = ref<ProducePlanLog[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const planId = ref()
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  logType: undefined,
  planId: undefined,
  linkId: undefined,
  inWarehouseId: undefined,
  outWarehouseId: undefined,
  productId: undefined,
  productName: undefined,
  productUnitId: undefined,
  createTime: []
})

const open = async (id: number, type: string) => {
  dialogVisible.value = true
  dialogTitle.value = type + '日志'
  formType.value = type
  planId.value = id
  getList()
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

/** 查询列表 */
const getList = async () => {
  try {
    queryParams.planId = planId
    queryParams.logType = formType
    const data = await ProducePlanLogApi.getProducePlanLogPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}
</script>
